package com.ildan.app.toilet;

import com.google.android.maps.OverlayItem;
import com.ildan.app.toilet.R;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class BalloonOverlayView extends FrameLayout{
	private LinearLayout layout;
	private TextView title;
	private TextView snippet;
	
	public BalloonOverlayView(Context context, int balloonBottomOffset) {
		super(context);
		
		layout = new LinearLayout(context);
		layout.setVisibility(View.VISIBLE);
		
		setPadding(10, 0, 10, balloonBottomOffset);
		LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
		View mView = mInflater.inflate(R.layout.balloon_overlay, layout);
		//title = (TextView)mView.findViewById(R.id.balloon_item_title);
		snippet = (TextView)mView.findViewById(R.id.balloon_item_snippet);
		
		ImageView closeBtn = (ImageView) mView.findViewById(R.id.close_img_button);
		closeBtn.setOnClickListener(onClickListener);
		
		FrameLayout.LayoutParams frameParams = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
		frameParams.gravity = Gravity.NO_GRAVITY;
		
		addView(layout, frameParams);
	}
	
	OnClickListener onClickListener = new OnClickListener() {
		public void onClick(View v) {
			layout.setVisibility(View.INVISIBLE);
		}
	};
	
	/**
	 * Sets the view data from a given overlay item.
	 * 
	 * @param item - The overlay item containing the relevant view data
	 * (title and snippet).
	 */
	public void setData(OverlayItem item){
		layout.setVisibility(View.VISIBLE);
		
		/*if(item.getTitle() != null){
			title.setVisibility(View.VISIBLE);
			title.setText(item.getTitle());
		}else{
			title.setVisibility(View.GONE);
		}*/
		
		if(item.getSnippet() != null){
			snippet.setVisibility(View.VISIBLE);
			snippet.setText(item.getSnippet());
		}else{
			snippet.setVisibility(View.GONE);
		}
	}
}
